package com.tg.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tg.app.R;
import com.tg.app.bean.WifiItem;
import com.tange.base.toolkit.StringUtils;

import java.util.List;

/**
 * Describe:
 * Created by Rance Rang on 2019-07-31.
 * <p>
 * Copyright (c) Tange.Inc All rights reserved.
 */
public class WifiAdapter extends BaseAdapter {
    private  Context context;
    private List<WifiItem> list;

    public WifiAdapter(Context context, List<WifiItem> list){
        this.context = context;
        this.list  = list;
    }
    @Override
    public int getCount() {
        return list==null?0:list.size();
    }


    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        WifiHolder   regionHolder ;
        if (view ==null){
            view = LayoutInflater.from(this.context).inflate(R.layout.wifi_item,null);
            regionHolder  = new WifiHolder();
            regionHolder.tvName  = view.findViewById(R.id.tv_name);
            regionHolder.tvSave  = view.findViewById(R.id.tv_save);
            view.setTag(regionHolder);
        }else {
            regionHolder = (WifiHolder) view.getTag();
        }

        regionHolder.tvName.setText(list.get(i).getUuid());
        regionHolder.tvSave.setVisibility(StringUtils.isEmpty(list.get(i).getPassword())? View.GONE : View.VISIBLE);
        return view;
    }

    static class  WifiHolder{
        TextView  tvName;
        TextView  tvSave;
    }
}
